package com.baby.work.domain.reflection;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Student {
    public String name;
    private int store;

    public Student (){
        System.out.println("default constructor");
    }

    private Student (String name) {
        this.name = name;
        System.out.println("private constructor");
    }

    public static void main(String[] args) throws Exception {
        Class studentClass = Student.class;
        Field[] fields = studentClass.getFields();
        for (Field field : fields) {
            System.out.println("fields: " + field.toString());
        }

        Constructor constructor = studentClass.getConstructor(null);
        Student student = (Student) constructor.newInstance();
        Field field2 = studentClass.getDeclaredField("store");
        field2.set(student, 4);
        System.out.println(student.store);
        System.out.println(field2.get(student));
    }
}
